blob: cc5f0891d3579ada651446b47c26962730f24af7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# dotfiles/home/.bashrc -> /home/$USER/.bashrc
# Author: Mountain Man
# Test for an interactive shell.
if [[ $- != *i* ]] ; then
return
fi
# Add to PATH
PATH=$PATH:/home/mountainman/.cargo/bin/
########################################################################
# PS1 - Primary prompt displayed before each command
####################################################
# The PS1 prompt is constructed piece-by-piece by concatenating each
# component to the previous component. Parts of the prompt are colored
# conditionally based on what kind of user is logged in.
#
# Breakdown of PS1 components:
# [TTY#] [DATE TIME] [USER HOST] [(BRANCH) DIR] >
#
# Example of what the prompt should look like:
# [1] [2023-03-28 16:02:55] [user host] [(stable) /etc/portage] >
########################################################################
# Set colors for easy reading
PS1_COLOR_RESET="\[\e[0m\]"
PS1_COLOR_GREY="\[\e[90m\]"
PS1_COLOR_RED="\[\e[91m\]"
PS1_COLOR_YELLOW="\[\e[33m\]"
PS1_COLOR_BLUE="\[\e[94m\]"
PS1_COLOR_CYAN="\[\e[96m\]"
PS1_BLINK_ON="\E[5m"
PS1_BLINK_OFF="\E(B\E\m"
if [[ "$(id -u)" == 0 ]]; then # if root
PS1_COLOR_MAIN=$PS1_COLOR_RED # set main color red
elif [[ "$USER" == *"-dev" ]]; then # if -dev account
PS1_COLOR_MAIN=$PS1_COLOR_YELLOW # set main color yellow
else # all other accounts
PS1_COLOR_MAIN=$PS1_COLOR_GREY # set main color grey
fi
# Start with a blank PS1 prompt
PS1=""
# [TTY#] [DATE TIME]
PS1+=$PS1_COLOR_MAIN
TTY_NUM=$(ps -p $$ -o tty= | tr -dc '0-9')
PS1+="[$TTY_NUM] [\D{%F} \t] "
PS1+=$PS1_COLOR_RESET
# [SSH USER@HOST]
PS1+="$PS1_COLOR_MAIN[$PS1_COLOR_RESET" # [
if [[ "$SSH_TTY" == "/dev/pts"* ]]; then # if this is SSH session
PS1+=$PS1_COLOR_CYAN #
PS1+="SSH " # add "SSH "
PS1+=$PS1_COLOR_RESET
fi
PS1+="$PS1_COLOR_CYAN\u$PS1_COLOR_RESET" # USER
PS1+="$PS1_COLOR_GREY@$PS1_COLOR_RESET" # @
PS1+="$PS1_COLOR_BLUE\h$PS1_COLOR_RESET" # HOST
PS1+="$PS1_COLOR_MAIN] $PS1_COLOR_RESET" # ]
# [(BRANCH) DIR] >
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' \
| awk '{$1=$1;print}'
}
PS1+="$PS1_COLOR_MAIN[$PS1_COLOR_RESET" # [
PS1+="\$(parse_git_branch) " # (BRANCH)
PS1+="$PS1_COLOR_CYAN\w$PS1_COLOR_RESET" # DIR
PS1+="$PS1_COLOR_MAIN] $PS1_BLINK_ON > $PS1_BLINK_OFF $PS1_COLOR_RESET" # ] >
########################################################################
########################################################################
# PS2 - Secondary prompt displayed when a command needs more input
##################################################################
PS2=" > "
########################################################################
########################################################################
# Aliases
#########
alias wget="wget -c --tries=10 --timeout=10 --waitretry=30s"
alias ls="exa -1aFghlmU --git --color=always --sort=name --time-style=iso --group-directories-first"
########################################################################
########################################################################
# Fixes for Emacs vterm
#######################
vterm_printf() {
if [ -n "$TMUX" ] && ([ "${TERM%%-*}" = "tmux" ] || [ "${TERM%%-*}" = "screen" ]); then
# Tell tmux to pass the escape sequences through
printf "\ePtmux;\e\e]%s\007\e\\" "$1"
elif [ "${TERM%%-*}" = "screen" ]; then
# GNU screen (screen, screen-256color, screen-256color-bce)
printf "\eP\e]%s\007\e\\" "$1"
else
printf "\e]%s\e\\" "$1"
fi
}
if [[ "$INSIDE_EMACS" = 'vterm' ]]; then
function clear() {
vterm_printf "51;Evterm-clear-scrollback";
tput clear;
}
fi
vterm_prompt_end(){
vterm_printf "51;A$(whoami)@$(hostname):$(pwd)"
}
PS1=$PS1'\[$(vterm_prompt_end)\]'
########################################################################
|